package cn.dakaqi.entities.user;


import cn.dakaqi.entities.IdEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.Cacheable;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.sql.Timestamp;

/**
 * @author beliveli on 2016/5/29/0029
 */
@EqualsAndHashCode(callSuper = false)

@Entity
@Table(name = "U_USER_OPENID")
@Data
@ToString
public class UserOpenId extends IdEntity
{
    private static final long serialVersionUID = 5868316381940262221L;
    private String memberCode;
    private int type;
    private String openId;
    private Timestamp createTime;
    private int effectiveTime; //ss
    private String client;

    public static UserOpenId build(String memberCode,Integer type,String openId,Timestamp createTime,Integer effectiveTime,String client){
        UserOpenId userOpenId = new UserOpenId();
        userOpenId.setOpenId(openId);
        userOpenId.setMemberCode(memberCode);
        userOpenId.setType(type);

        if(createTime != null){
            userOpenId.setCreateTime(createTime);
        }

        if(effectiveTime != null){
            userOpenId.setEffectiveTime(effectiveTime);
        }
        
        if(StringUtils.isEmpty(client)){
            userOpenId.setClient(client);
        }

        return userOpenId;
    }

}
